import enumMesg from "../../em/enumMesg"
import supMount from "../../sup/supMount"
import explorer from "../../api/ts/api_explorer"
import infosModule from "../../glo/infosModule"

const { ccclass, property } = cc._decorator;
@ccclass
export default class myselfMount extends supMount {
    @property(cc.Sprite)
    private spLogo:cc.Sprite     = null; //头像
    @property(cc.Label)    
    private laName:cc.Label      = null; //昵称
    @property(cc.RichText)     
    private allian:cc.RichText   = null; //联盟
    @property(cc.Label)     
    private laCoin:cc.Label      = null; //资产
    @property(cc.Label)
    private laCoinLM:cc.Label    = null; //盟币
    start(){
       let data:s2c_loginResult     = infosModule.getData(enumMesg.s2c_loginResult)
       
       if(data){
            //昵称
            this.laName.string = data.nickname
            //联盟
            this.allian.string = this.clubID()
            //资产
            this.laCoin.string = data.coin.toString()
            //盟币
            this.laCoinLM.string = data.silver.toString()
            //头像
            explorer.imageRemote(data.logo,(error: Error, texture: any)=>{
                if(!error){
                    this.spLogo.spriteFrame = new cc.SpriteFrame(texture)
                }
            })
            
       }
    }

    public clubID():string {
        let datas:s2c_clubClubs = infosModule.getData(enumMesg.s2c_clubClubs)
        let clubs:s2c_clubClub[] = datas.clubs
        switch(clubs.length){
            case 0:{
                let v0 = "未加入联盟"
                let v1 = "请加入联盟"
                return `<color=#88888888>${v0}-</c><color=#88888888>(${v1})</color>`
            }break
            default:{
                let text:string = ""
                clubs.forEach(club => {
                    let v0:string = club.club.clubName
                    let v1:number = club.club.clubID
                    text += `<color=#88888888>${v0}</c><color=#88888888>(${v1})</color>`
                })
                return text
            }break
        }
    }
}
